package detect;

import interfaces.Detect;

import java.util.Map;

import org.jsoup.nodes.Document;

import com.google.gson.Gson;

import entities.CmsTechnology;
import entities.Domain;

public class DetectCmsVanillaForums implements Detect {

	@Override
	public void getInfo(Map<String, Object> obj) {
		Document doc = (Document) obj.get("doc");
		Domain domain = (Domain) obj.get("domain");

		CmsTechnology cmsTechnology = (CmsTechnology) new Gson().fromJson(
				domain.getCmsTechnology(), CmsTechnology.class);

		if (cmsTechnology == null) {
			cmsTechnology = new CmsTechnology();
		}

		try {

			String cms_name = "";
			String cms_version = "";

			if (doc.select("body").attr("id")
					.equalsIgnoreCase("vanilla_discussions_index")) {
				cms_name = "Vanilla Forums";

				cmsTechnology.setN(cms_name);
				cmsTechnology.setV(cms_version);
			}

			if (!cms_name.isEmpty()) {
				domain.setCmsTechnology(new Gson().toJson(cmsTechnology));
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
